<?php

namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Session;
class Classify extends Controller{
    /****
     * Class register          	生活圈
     * @$headline[array]    		分类
     * @date                	  2020/05/25
     * @package application\index\controller\Classify
    */
    public function headline(){
       $headline = Db::name('headline')->where(['status'=>1])->select();
       if($headline){
       		$arr = [
		       'state'      => 1,
           'headline'   =>$headline,
		       'message'    => "查询成功"
	       	];
       }else{
       		$arr = [
		       'state'      => 0,
		       'message'    => "查询失败"
	       	];
       }
       return json($arr);
    }
    /**** 
     * Class register                   校园资讯
     * @$headline_consult[array]        内容    
     * @date                            2020/05/25
     * @package application\index\controller\Classify  
    */ 
    public function headline_consult(){
       $headline_id = input('headline_id');
       $headline_consult = Db::name('headline_consult a')
						 ->join('user b','b.id = a.user_id')
						 ->where(['a.headline_id'=>$headline_id])
						 ->paginate(5);
       if($headline_consult){
          $arr = [
           'state'              => 1,
           'headline_consult'   =>$headline_consult,
           'message'            => "查询成功"
          ];
       }else{
          $arr = [
           'state'              => 0,
           'message'            => "查询失败"
          ];
       }
       return json($arr);
    }
    /**** 
     * Class register                   校园招聘兼职
     * @$headline_consult[array]        内容
     * @date                            2020/05/25
     * @package application\index\controller\Classify
    */
    public function headline_moonlighted(){
       // $headline_id = input('headline_id');
       $headline_moonlighted = Db::name('headline_moonlighted')->where(['status'=>1,'audit'=>1])->select();
       if($headline_moonlighted){
          $arr = [
           'state'              => 1,
           'headline_moonlighted'   =>$headline_moonlighted,
           'message'            => "查询成功"
          ];
       }else{
          $arr = [
           'state'              => 0,
           'message'            => "查询失败"
          ];
       }
       return json($arr);
  }
  public function moonlighted_details(){
       $details_id = input('details_id');
       $headline_moonlighted = Db::name('headline_moonlighted')->where(['status'=>1,'id'=>$details_id])->find();
       if($headline_moonlighted){
          $arr = [
           'state'              => 1,
           'headline_moonlighted'   =>$headline_moonlighted,
           'message'            => "请求成功"
          ];
       }else{
          $arr = [
           'state'              => 0,
           'message'            => "请求失败"
          ];
       }
       return json($arr);
  }
  
  
  public function headline_used_type(){
	   $headline_used_type = Db::name('headline_used_type')->where(['status'=>1])->select();
       if($headline_used_type){
          $arr = [
           'state'              => 1,
           'headline_used_type'   =>$headline_used_type,
           'message'            => "查询成功"
          ];
       }else{
          $arr = [
           'state'              => 0,
           'message'            => "查询失败"
          ];
       }
       return json($arr);
  }
    /**** 
     * Class register                  二手市场
     * @$headline_consult[array]        内容
     * @date                            2020/05/25
     * @package application\index\controller\Classify
    */
  public function headline_used(){
       $headline_id = input('headline_id');
       $headline_used = Db::name('headline_used a')
	   ->join('user b','a.user_id = b.id ','LEFT')
	   ->where(['a.headline_id'=>$headline_id])
	   ->field('a.*,b.id as userid,b.nickname,b.avatar,b.bio')
	   ->paginate(5);
       if($headline_used){
          $arr = [
           'state'              => 1,
           'headline_used'   =>$headline_used,
           'message'            => "查询成功"
          ];
       }else{
          $arr = [
           'state'              => 0,
           'message'            => "查询失败"
          ];
       }
       return json($arr);
  }  
   public function headline_used_details(){
       $sid = input('sid');
       $headline_used = Db::name('headline_used a')
	   ->join('user b','a.user_id = b.id ','LEFT')
	   ->where(['a.id'=>$sid])
	   ->field('a.*,b.id as userid,b.nickname,b.avatar,b.bio')
	   ->find();
       if($headline_used){
          $arr = [
           'state'              => 1,
           'headline_used'   =>$headline_used,
           'message'            => "查询成功"
          ];
       }else{
          $arr = [
           'state'              => 0,
           'message'            => "查询失败"
          ];
       }
       return json($arr);
  }
  
  public function post_delivery(){
     $user_id = input('user_id');
     $type = input('type');
     if($type == 1){
        $headline_moonlighted =Db::name('headline_moonlighted a')
                            ->join('deliver b','find_in_set(b.moonlighted_id,a.id)','LEFT' )
                            ->join('user c','find_in_set(b.user_id,c.id)','LEFT')
                            ->join('personal d','d.user_id = b.user_id')
                            ->where(['a.user_id'=>$user_id,'b.type'=>1])
                            ->select();
     }else{
        $headline_moonlighted =Db::name('headline_moonlighted a')
                            ->join('deliver b','find_in_set(b.moonlighted_id,a.id)','LEFT' )
                            ->join('user c','find_in_set(b.user_id,c.id)','LEFT')
                            ->join('personal d','d.user_id = b.user_id')
                            ->where(['a.user_id'=>$user_id,'b.type'=>0])
                            ->select();
     }
     if($headline_moonlighted){
          $arr = [
           'state'                  => 1,
           'headline_moonlighted'   =>$headline_moonlighted,
           'message'                => "查询成功"
          ];
       }else{
          $arr = [
           'state'                  => 1,
           'headline_moonlighted'   =>'',
           'message'                => "查询失败"
          ];
       }
       return json($arr);

  }
  
  
  
   public function post_management(){
      $user_id = input('user_id');
      $type = input('type');
      if($type == 1){
        $headline_moonlighted =Db::name('headline_moonlighted')->where(['user_id'=>$user_id,'type'=>1])->select();
      }else{
        $headline_moonlighted =Db::name('headline_moonlighted')->where(['user_id'=>$user_id,'type'=>0])->select();
      }
      if($headline_moonlighted){
          $arr = [
           'state'                  => 1,
           'headline_moonlighted'   =>$headline_moonlighted,
           'message'                => "查询成功"
          ];
       }else{
          $arr = [
           'state'                  => 1,
           'headline_moonlighted'   =>'',
           'message'                => "查询失败"
          ];
       }
       return json($arr);
      

   } 
    

   

}
